#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
#define SIZE 1024
int main()
{
    int fd = -1;
    int ret = -1;
    // 1.以只写的方式打开管道文件
    fd = open("fifo", O_WRONLY);
    char buffer[SIZE];
    if (fd == -1)
    {
        perror("open");
        return 1;
    }
    printf("打开成功\n");
    int i = 0;
    // 写管道
    while (1)
    {
        memset(buffer, 0, sizeof(buffer));
        sprintf(buffer, "你好你好:%d", i++);
        ret = write(fd, buffer, strlen(buffer));
        if (ret <= 0)
        {
            perror("write");
            break;
        }
        printf("写入成功：%d\n", ret);
        sleep(1);
    }
    // 关闭文件
    close(fd);
    return 0;
}